package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Ticket;
import cn.wolfcode.trip.base.query.TicketQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.ITicketService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/ticket")
public class TicketContr {
    @Autowired
    private ITicketService ticketService;
    @Autowired
    private IRegionService regionService;

    @RequestMapping("/list")
    public String list( @ModelAttribute("qo") TicketQueryObject qo,Model model){
        model.addAttribute("pageInfo",ticketService.query(qo));
        model.addAttribute("regions",regionService.listAll(null));
        return "ticket/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Ticket ticket){
        JsonResult jsonResult = new JsonResult();
            if (ticket.getId() == null) {
                ticketService.save(ticket);
            }else{
                ticketService.update(ticket);
            }
        return jsonResult;
    }
}
